package com.database;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class DBFrame extends JFrame implements ActionListener{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private List<String> tables;
	private JPanel function_jp;
	private JPanel table_jp;
	private JPanel content_jp;
	private JPanel result_jp;
	public DBFrame(List<String> tables) {
		this.tables = tables;
		this.setTitle("DB");
		this.setBounds(300, 100, 1000, 600);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setAlwaysOnTop(true);
		this.setLayout(new BorderLayout());
//		this.setResizable(false);
		function_jp = new JPanel();
		function_jp.setSize(1000, 50);
		function_jp.setBackground(Color.BLUE);
		function_jp.setLayout(new FlowLayout(FlowLayout.LEFT));
		this.add(function_jp, BorderLayout.NORTH);
		table_jp = new JPanel();
		table_jp.setSize(100, 400);
		table_jp.setBackground(Color.DARK_GRAY);
		this.add(table_jp, BorderLayout.WEST);
		content_jp = new JPanel();
		content_jp.setSize(900, 400);
		content_jp.setBackground(Color.WHITE);
		this.add(content_jp, BorderLayout.CENTER);
		result_jp = new JPanel();
		result_jp.setSize(1000, 150);
		result_jp.setBackground(Color.cyan);
		this.add(result_jp, BorderLayout.SOUTH);
		setFunction();
		createTables();
	}
	public void setFunction(){
		JButton jb1 = new JButton("exec");
		jb1.setBounds(10, 10, 30, 20);
		function_jp.add(jb1);
	}
	public void createTables(){
		if(tables==null){
			return;
		}
//		table_jp.setLayout(null);
		int size = tables.size();
		JButton[] table_jb = new JButton[size];
		for(int i=0;i<size;i++){
			table_jb[i] = new JButton(tables.get(i));
			table_jb[i].setBounds(20, 10+30*i, 60, 20);
			table_jp.add(table_jb[i]);
		}
		JLabel jl1 = new JLabel("aa");
		table_jp.add(jl1);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		
	}

	public static void main(String[] args) {
		List<String> test = new ArrayList<String>();
		test.add("table1");
		test.add("table2");
//		test.add("table3");
//		test.add("table4");
		DBFrame dbf = new DBFrame(test);
		dbf.setVisible(true);
	}
}
